package ym.config;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.sql.DataSource;


/**
 * 记住我配置类
 */
@Configuration
public class RememberMeConfig {
    @Autowired
    private DataSource dataSource;

    /**
     * 将 “记住我” 的信息持久化到数据库中
     * @return
     */
    @Bean
    public PersistentTokenRepository getPersistentTokenRepository() {
        // 创建一个JdbcTokenRepositoryImpl实例来存储令牌信息到数据库
        JdbcTokenRepositoryImpl tokenRepository = new JdbcTokenRepositoryImpl();
        //设置数据源
        tokenRepository.setDataSource(dataSource);
        //自动建表，第一次启动时需要，第二次启动时注释掉
//        tokenRepo1sitory.setCreateTableOnStartup(true);
        return tokenRepository;
    }
}
